package com.ynet.middleground.riskmanage.mq.producer;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.mq.SourceBlchzt;

/**
 * @ClassName BlchztProducer
 * @Description TODO
 * @Author zhangyongbin
 * @Date 2020/8/20 17:24
 * @Version 1.0
 */
@EnableBinding({SourceBlchzt.class})
@Component
public class BlchztProducer {

    @Autowired
    private SourceBlchzt source;

    /**
     * 入池状态信息加入消息队列
     *
     * @param msgMap
     */
    public void sendMessagesBlchztIn(Map<String, Object> msgMap) {
        IfpLogger.info("mq", "MQ 入池状态信息，往Binding-{}推送信息-{}", SourceBlchzt.JKZTFK_TO_QQJY_BLCHZT_PUSH, msgMap);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msgMap, messageHeaders);
        this.source.blchztNotice().send(message);
    }

    /**
     * 出池状态信息加入消息队列
     *
     * @param msgMap
     */
    public void sendMessagesBlchztOut(Map<String, Object> msgMap) {
        IfpLogger.info("mq", "MQ 出池状态信息，往Binding-{}推送信息-{}", SourceBlchzt.JKZTFK_TO_QQJY_BLCHZT_PUSH, msgMap);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "out");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msgMap, messageHeaders);
        this.source.blchztNotice().send(message);
    }

    public void testIn() {
        // 消息要素
        Map<String, Object> msgMap = new HashMap<>(15);
        msgMap.put("traceId", "03702190010510222047");
        msgMap.put("requestTime", "20211001010000");
        msgMap.put("channel", "000");
        msgMap.put("orderType", "0");
        msgMap.put("orderNum", "03702190010510222047");
        msgMap.put("serialNo", "F0F8306A4C294E73A6B3835E06ADBE1C");
        msgMap.put("status", "00");
        msgMap.put("currency", "RMB");
        msgMap.put("reason", "入池成功");
        msgMap.put("newPoolDate", "2021-03-16");
        IfpLogger.info("mq", "MQ 核心入池状态信息，往Binding-{}推送信息-{}", SourceBlchzt.BLXD_TO_JKZTFK_BLCHZT_PUSH, msgMap);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msgMap, messageHeaders);
        this.source.notice().send(message);
    }

    public void testOut() {
        // 消息要素
        Map<String, Object> msgMap = new HashMap<>(15);
        msgMap.put("traceId", "03702190010507961032");
        msgMap.put("requestTime", "20210800010");
        msgMap.put("channel", "Q00");
        msgMap.put("orderType", "0");
        msgMap.put("orderNum", "03702190010507961032");
        msgMap.put("serialNo", "2ED7166B334345209CD82B1A7E959CB4");
        msgMap.put("status", "10");
        msgMap.put("reason", "出池成功");
        msgMap.put("outPoolDate", "2021-03-16");
        msgMap.put("currency", "RMB");
        IfpLogger.info("mq", "MQ 核心出池状态信息，往Binding-{}推送信息-{}", SourceBlchzt.BLXD_TO_JKZTFK_BLCHZT_PUSH, msgMap);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "out");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msgMap, messageHeaders);
        this.source.notice().send(message);
    }

}
